<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>高考志愿填报辅导系统</title>
    <link rel="stylesheet" type="text/css" href="../../../assets/edu/layui/css/layui.css"
          th:href="@{/assets/edu/layui/css/layui.css}">
    <link rel="stylesheet" type="text/css" href="../../../assets/edu/css/css.css" th:href="@{/assets/edu/css/css.css}">
    <script type="text/javascript" src="../../../assets/edu/js/jquery-1.11.3.js"
            th:src="@{/assets/edu/js/jquery-1.11.3.js}"></script>
    <script type="text/javascript" src="../../../assets/edu/layui/layui.js"
            th:src="@{/assets/edu/layui/layui.js}"></script>
    <script type="text/javascript" src="../../../assets/edu/js/common.js"
            th:src="@{/assets/edu/js/common.js?v=201803171720}"></script>
</head>
<body th:inline="none">
<div class="pad10">
    <blockquote class="layui-elem-quote">
        您的成绩：位次：<span id="ranking" th:text="${candidate.ranking}">209524</span>&nbsp;&nbsp;
        分数：<span th:text="${candidate.totalScore}">400</span>&nbsp;&nbsp;
        指数：<span th:text="${zs}">1%</span>&nbsp;&nbsp;
        科目：<span
            th:if="${candidate.physics eq 1}">物理&nbsp;</span>
        <span th:if="${candidate.chemistry eq 1}">化学&nbsp;</span><span th:if="${candidate.biology eq 1}">生物&nbsp;</span>
        <span th:if="${candidate.technology eq 1}">技术&nbsp;</span>
        <span th:if="${candidate.history eq 1}">历史&nbsp;</span>
        <span th:if="${candidate.geography eq 1}">地理&nbsp;</span>
        <span th:if="${candidate.politics eq 1}">政治&nbsp;</span>
    </blockquote>
    <input type="hidden" th:value="${candidate.id}" id="hid_id">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
        <legend>设置“冲、稳、保”位次区间(您输入的位次"<span style="color: #ffd75a" th:text="${candidate.ranking}">209524</span>"不可调整)
        </legend>
    </fieldset>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">冲</label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="c_min" id="c_min" autocomplete="off" class="layui-input" th:value="${cMin}">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="c_max" id="c_max" th:value="${candidate.ranking}" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-inline">
                <label class="layui-form-label">稳</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="w_min" id="w_min" th:value="${candidate.ranking}" class="layui-input">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="w_max" id="w_max" autocomplete="off" class="layui-input"
                           th:value="${wMax}">
                </div>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-inline">
                <label class="layui-form-label">保</label>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="b_min" id="b_min" autocomplete="off" class="layui-input"
                           th:value="${wMax}">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline" style="width: 100px;">
                    <input type="text" name="b_max" id="b_max" autocomplete="off" class="layui-input"
                           th:value="${bMax}">
                </div>
            </div>
        </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
        <legend>查询条件</legend>
    </fieldset>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">意向专业</label>
        <div class="layui-input-inline" style="width: 350px">
            <input placeholder="请输入意向专业" class="layui-input" id="zymc">
        </div>
        <div class="layui-input-inline" style="width: 180px;">
            <a class="layui-btn"
               href="http://www.moe.gov.cn/srcsite/A08/moe_1034/s3882/201209/W020170420567985974471.doc"
               target="_blank">教育部本科专业目录</a>
        </div>
        <div class="layui-input-inline" style="width: 100px;">
            <a target="_blank" class="layui-btn" href="http://www.cdgdc.edu.cn/xwyyjsjyxx/xkpgjg/">
                教育部学科等级评估
            </a>
        </div>
    </div>
</div>
</div>
<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">意向省份</label>
    <button class="layui-btn" data-type="chooseProvince">选择地区</button>
    <span style="color:red;">(点击此按钮选择地区)</span>
    <div class="layui-input-block">
        <input type="hidden" id="province_code">
        <textarea placeholder="请选择意向省份" class="layui-textarea" disabled id="province_name"></textarea>
    </div>
</div>
<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">意向学校</label>
    <button class="layui-btn" data-type="chooseSchool">选择学校</button>
    <span style="color:red;">(点击此按钮选择学校)</span>
    <div class="layui-input-block">
        <input type="hidden" id="school_code">
        <textarea placeholder="请选择意向学校" class="layui-textarea" disabled id="school_name"></textarea>
    </div>
</div>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" data-type="search">生成志愿</button>
    </div>
</div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
    <legend>“冲、稳、保”志愿筛选结果；推荐结果仅供参考，请结合自身情况进行填报
    </legend>
</fieldset>
<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">冲</label>
        <div class="layui-input-inline" style="width: 100px;">
            <div id="c_result">

            </div>
        </div>
        <button class="layui-btn" data-type="cSearch">查看志愿</button>
    </div>
    <div class="layui-inline">
        <div class="layui-inline">
            <label class="layui-form-label">稳</label>
            <div class="layui-input-inline" style="width: 100px;">
                <div id="w_result">

                </div>
            </div>
        </div>
        <button class="layui-btn" data-type="wSearch">查看志愿</button>
    </div>
    <div class="layui-inline">
        <div class="layui-inline">
            <label class="layui-form-label">保</label>
            <div class="layui-input-inline" style="width: 100px;">
                <div id="b_result">

                </div>
            </div>
        </div>
        <button class="layui-btn" data-type="bSearch">查看志愿</button>
    </div>
</div>
</div>
<div class="m-modal" id="province" style="display: none;">
    <form class="layui-form" action="">
        <div class="layui-form-item" pane="">
            <div class="layui-input-block">
                <input type="checkbox" name="pr" th:each="province : ${provinces}" th:value="${province.code}"
                       th:title="${province.name}" lay-skin="primary">
            </div>
        </div>
    </form>
</div>
<div class="m-modal" id="school" style="display: none;">
    <form class="layui-form" action="" lay-filter="example">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">院校名称</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="yxmc">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"></label>
                <a href="javascript:;" class="layui-btn ayui-btn-normal bg-blue " data-type="reloadSchool">
                    <i class="iconfont">&#xe606;</i> 查询</a>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">院校性质</label>
            <div class="layui-input-block">
                <input type="checkbox" id="sf985" lay-skin="primary" title="985" checked="">
                <input type="checkbox" id="sf211" lay-skin="primary" title="211">
                <input type="checkbox" id="sfsyl" lay-skin="primary" title="双一流">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">办学类型</label>
            <div class="layui-input-inline">
                <select id="bxlx">
                    <option value="">请选择办学类型</option>
                    <option value="1">公办</option>
                    <option value="2">民办</option>
                    <option value="3">独立学院</option>
                    <option value="4">中外合作</option>
                </select>
            </div>
        </div>
        <div class="gkwh-tb">
            <div class="layui-btn-group">
                <a class="layui-btn layui-btn-primary  layui-btn-sm" data-type="addSchool"><i class="iconfont"></i>增加意向学校</a>
                <a class="layui-btn layui-btn-primary  layui-btn-sm" data-type="clearSchool"><i
                        class="iconfont"></i>清空意向学校</a>
            </div>
            <table id="school-list"></table>
        </div>
    </form>
</div>
<script>
    layui.use(['table', 'form'], function () {
        var $ = layui.jquery
            , table = layui.table;
        table.render({
            elem: '#school-list'
            , url: '/school/'
            , cols: [[
                {field: 'id', title: 'id', checkbox: true, sort: true}
                , {field: 'yxmc', title: '院校名称', sort: true}
            ]]
            , id: 'schoolTable'
            , request: {
                pageName: 'currentPage' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , response: {
                statusCode: 90000 //成功的状态码，默认：0
                , countName: 'count' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            }
            , even: true
            , page: {theme: '#2d5eb7'}
            , done: function (res, curr, count) {
                if (res.code == 30002) {
                    layer.msg(res.msg);
                    setTimeout(function () {
                        top.location.href = "/login";
                    }, 5000);
                } else if (res.code != 90000) {
                    layer.msg(res.msg);
                }
            }
        });
        var yxName = [];
        var yxCode = [];
        var active = {
            search: function () {
                var c_min = $("#c_min").val();
                var c_max = $("#c_max").val();
                var w_min = $("#w_min").val();
                var w_max = $("#w_max").val();
                var b_min = $("#b_min").val();
                var b_max = $("#b_max").val();
                var id = $("#hid_id").val();
                if (isEmpty(c_min) || isEmpty(c_max)) {
                    layer.msg("冲位次区间不能为空");
                    return;
                }
                if (isEmpty(w_min) || isEmpty(w_max)) {
                    layer.msg("稳位次区间不能为空");
                    return;
                }
                if (isEmpty(b_min) || isEmpty(b_max)) {
                    layer.msg("保位次区间不能为空");
                    return;
                }
                var provinceCode = $("#province_code").val();
                var zymc = $("#zymc").val();
                var schoolCode = "";
                for (var i = 0, len = yxCode.length; i < len; i++) {
                    schoolCode += "" + yxCode[i];
                    if (i < len - 1) {
                        schoolCode += ",";
                    }
                }
                layer.load();
                $.get("/candidate/application", {
                    "c_min": c_min
                    , "c_max": c_max
                    , "w_min": w_min
                    , "w_max": w_max
                    , "b_min": b_min
                    , "b_max": b_max
                    , "id": id
                    , "provinceCode": provinceCode
                    , "zymc": zymc
                    , "schoolCode": schoolCode
                }, function (res) {
                    layer.closeAll();
                    if (res.code == 30002) {
                        layer.msg(res.msg);
                        setTimeout(function () {
                            top.location.href = "/login";
                        }, 5000);
                    } else if (res.code != 90000) {
                        layer.msg(res.msg);
                    } else {
                        $("#c_result").html("推荐志愿:" + res.data.cMajor + "，分布于" + res.data.cSchool + "所院校中");
                        $("#w_result").html("推荐志愿:" + res.data.wMajor + "，分布于" + res.data.wSchool + "所院校中");
                        $("#b_result").html("推荐志愿:" + res.data.bMajor + "，分布于" + res.data.bSchool + "所院校中");
                    }
                });
            }
            , cSearch: function () {
                changeToDetail(yxCode, '1');
            }
            , wSearch: function () {
                changeToDetail(yxCode, '2');
            }
            , bSearch: function () {
                changeToDetail(yxCode, '3');
            }
            , chooseProvince: function () {
                layer.open({
                    type: 1
                    , skin: 'layui-layer-demo t-layer-add' //样式类名
                    , closeBtn: 1
                    , anim: 2
                    , area: '800px'
                    , btn: ['确定', '取消']
                    , title: "省市选择"
                    , content: $("#province")
                    , yes: function (index, layero) {
                        var checked = $("input[name='pr']:checked");
                        var checkBoxValue = "";
                        var checkBoxTitle = "";
                        checked.each(function () {
                            checkBoxValue += $(this).val() + ",";
                            checkBoxTitle += $(this).next().children('span').text() + ",";
                        });
                        $("#province_code").val(checkBoxValue.substring(0, checkBoxValue.length - 1));
                        $("#province_name").val(checkBoxTitle.substring(0, checkBoxTitle.length - 1));
                        layer.closeAll();
                    }
                    , success: function (layero, index) {

                    }
                    , cancel: function (index, layero) {
                    }
                });

            }
            , chooseMajor: function () {
                layer.open({
                    type: 1
                    , skin: 'layui-layer-demo t-layer-add' //样式类名
                    , closeBtn: 1
                    , anim: 2
                    , area: '800px'
                    , btn: ['确定', '取消']
                    , title: "专业选择"
                    , content: $("#major")
                    , yes: function (index, layero) {
                        layer.closeAll();
                    }
                    , success: function (layero, index) {

                    }
                    , cancel: function (index, layero) {

                    }
                });
            }
            , chooseSchool: function () {
                layer.open({
                    type: 1
                    , skin: 'layui-layer-demo t-layer-add' //样式类名
                    , closeBtn: 1
                    , anim: 2
                    , area: '800px'
                    , btn: ['确定', '取消']
                    , title: "院校选择"
                    , content: $("#school")
                    , yes: function (index, layero) {
                        layer.closeAll();
                    }
                    , success: function (layero, index) {

                    }
                    , cancel: function (index, layero) {
                    }
                });

            }
            , addSchool: function () {
                var checkStatus = table.checkStatus('schoolTable');
                var data = checkStatus.data;
                if (data.length <= 0) {
                    layer.msg("请选择院校");
                    return;
                }
                for (var j = 0; j < data.length; j++) {
                    var ids = data[j].yxdh;
                    var name = data[j].yxmc;
                    if (yxCode.in_array(ids) == false) {
                        yxCode.push(ids);
                        yxName.push(name);
                    }
                }
                $("#school_name").val(yxName);
            }
            , clearSchool: function () {
                $("#school_name").val("");
                yxCode = [];
                yxName = [];
            }
            , reloadSchool: function () {
                var yxmc = $("#yxmc").val();
                var sf985 = "";
                if ($("#sf985").prop("checked")) {
                    sf985 = 1;
                }
                var sf211 = "";
                if ($("#sf211").prop("checked")) {
                    sf211 = 1;
                }
                var sfsyl = "";
                if ($("#sfsyl").prop("checked")) {
                    sfsyl = 1;
                }
                var bxlx = $("#bxlx").val();
                table.reload('schoolTable', {
                    page: {
                        curr: 1
                    }
                    , where: {
                        "yxmc": yxmc
                        , "sf985": sf985
                        , "sf211": sf211
                        , "sfsyl": sfsyl
                        , "bxlx": bxlx
                    }
                });
            }
        };
        $('.layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

    function changeToDetail(yxCode, type) {
        var zymc = $("#zymc").val();
        var min = 0;
        var max = 0;
        if (type == 1) {
            min = $("#c_min").val();
            max = $("#c_max").val();
        } else if (type == 2) {
            min = $("#w_min").val();
            max = $("#w_max").val();
        } else {
            min = $("#b_min").val();
            max = $("#b_max").val();
        }
        var id = $("#hid_id").val();
        var provinceCode = $("#province_code").val();
        $.ajax({
            url: '/candidate/sendMsg'
            , type: 'post'
            , dataType: 'json'
            , data: {
                "schoolCode": yxCode.toString(),
                "zymc": zymc,
                "id": id
            }
            , success: function (data) {
                if (data.code == 30002) {
                    layer.msg(data.msg);
                    setTimeout(function () {
                        top.location.href = "/login";
                    }, 5000);
                } else if (data.code != 90000) {
                    layer.msg(data.msg);
                } else {
                    window.open("/candidate/searchDetail?min=" + min + "&max=" + max + "&id=" + id + "&provinceCode=" + provinceCode
                        + "&schoolCodeSession=" + data.data.schoolCodeSession + "&majorCodeSession=" + data.data.majorCodeSession + "&type=" + type, "_blank", "toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width=1000, height=800");
                }
            }
        });
    }
</script>
<script>
    Array.prototype.in_array = function (element) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == element) {
                return true;
            }
        }
        return false;
    }
</script>
</body>
</html>